package com.example.administrator.qq;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;

import com.example.administrator.DB.DBManager;
import com.example.administrator.VO.UserInfo;

import static com.example.administrator.Util.ShowToastTime.showMyToast;

/**
 * Created by ykbboom on 2016/12/29.
 */
public class ModelActivity extends AppCompatActivity {

    private DBManager dbManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_model);
        Button btn = (Button)findViewById(R.id.timePointBtn);//计时模式按钮
        Button btn2 = (Button) findViewById(R.id.stepPointBtn);//限步模式按钮
        ImageButton btn3 = (ImageButton) findViewById(R.id.homepage);//返回主界面
        dbManager = new DBManager(ModelActivity.this);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            /**
             * 单机模式弹出购买道具对话框
             */
            public void onClick(View v) {
                //扣除用户一点体力
                UserInfo userInfo = dbManager.queryAll();
                if(userInfo.getBody_num()==0){
                    Toast toast=Toast.makeText(ModelActivity.this, "请补充体力~", Toast.LENGTH_LONG);
                    showMyToast(toast,1*1000);
                }else{
                    userInfo.setBody_num(userInfo.getBody_num()-1);
                    dbManager.updateBodyNum(userInfo);
                    Intent i = new Intent(ModelActivity.this,GameActivity.class);
                    startActivity(i);
                    ModelActivity.this.finish();
                }



//                new AlertDialog.Builder(ModelActivity.this)
//                        .setTitle("小提示")
//                        .setMessage("是否花费10金币购买神秘道具？")
//                        .setPositiveButton("购买", new DialogInterface.OnClickListener() {
//                            @Override
//                            public void onClick(DialogInterface dialog, int which) {
//                                //暂且不实现购买道具功能（与数据库连接扣除金币）
//                                //跳转到购买道具界面
//                            }
//                        })
//                        .setNegativeButton("放弃", new DialogInterface.OnClickListener() {
//                            @Override
//                            public void onClick(DialogInterface dialog, int which) {
//                                //跳转到游戏Activity
//                            }
//                        })
//                        .show();
            }
        });
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //扣除用户一点体力
                UserInfo userInfo = dbManager.queryAll();
                if(userInfo.getBody_num()==0){
                    Toast toast=Toast.makeText(ModelActivity.this, "请补充体力~", Toast.LENGTH_LONG);
                    showMyToast(toast,1*1000);
                }else{
                    userInfo.setBody_num(userInfo.getBody_num()-1);
                    dbManager.updateBodyNum(userInfo);
                    Intent i = new Intent(ModelActivity.this,Game2Activity.class);
                    startActivity(i);
                    ModelActivity.this.finish();
                }

            }
        });
        btn3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(ModelActivity.this,MainActivity.class);
                startActivity(i);
                ModelActivity.this.finish();
            }
        });
    }


}
